package com.qk.management.service.Impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qk.common.PageResult;
import com.qk.doman.clue.CustomerDO;
import com.qk.dto.customer.CustomerQueryDTO;
import com.qk.entity.Customer;
import com.qk.management.mapper.CustomerMapper;
import com.qk.management.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * @author 16778
 * @date 2025/10/15 11:24
 * @description
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public PageResult<CustomerDO> selectByPage(CustomerQueryDTO dto) {
        Page<CustomerDO> pageParam = new Page<>(dto.getPage(),dto.getPageSize());
        Page<CustomerDO> pages = customerMapper.selectByPage(pageParam,dto);
        return PageResult.<CustomerDO>builder()
                .total(pages.getTotal())
                .rows(pages.getRecords())
                .build();
    }

    @Override
    public void insert(Customer customer) {
        customer.setCreateTime(LocalDateTime.now());
        customer.setUpdateTime(LocalDateTime.now());
        this.baseMapper.insert(customer);
    }
}
